package Vista;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class LogIn {
	

	private JPanel mainPanel = new JPanel();
	private JLabel jlb_user, jlb_pass, jlb_sideImage, jlb_logoImage;
	private JTextField jtf_user;
	private JPasswordField jpf_pass;
	private JButton jb_signIn, jb_newAccount;
	
	protected void clearTextFields() {
		jtf_user.setText("");
		jpf_pass.setText("");
	}
	
	public LogIn() {
		initComponents();
	}

	private void initComponents() {
		mainPanel.setLayout(null);
		mainPanel.add(getJLabelUser());
		mainPanel.add(getJLabelPass());
		mainPanel.add(getJTextFieldUser());
		mainPanel.add(getJPasswordFieldPass());
		mainPanel.add(getJButtonSignIn());
		mainPanel.add(getJLabelSideImage());
		mainPanel.add(getJButtonNewAccount());
		mainPanel.add(getJLabelLogoImage());
		mainPanel.setSize(700, 500);
	}

	private JButton getJButtonNewAccount() {
		if (jb_newAccount == null) {
			jb_newAccount = new JButton();
			jb_newAccount.setBackground(Color.white);
			jb_newAccount.setForeground(Color.blue);
			jb_newAccount.setText("Crear cuenta");
			jb_newAccount.setBorderPainted(false);
			jb_newAccount.setHorizontalAlignment(SwingConstants.LEFT);
			jb_newAccount.setOpaque(false);
			jb_newAccount.setBounds(525, 425, 130, 40);

		}
		return jb_newAccount;
	}

	private JLabel getJLabelSideImage() {
		if (jlb_sideImage == null) {
			jlb_sideImage = new JLabel(new ImageIcon(("./images/app.png")));
	        jlb_sideImage.setLayout(new FlowLayout());
	        jlb_sideImage.setBounds(0, 0, 300, 500);
		}
		return jlb_sideImage;
	}
	
	private JLabel getJLabelLogoImage() {
		if (jlb_logoImage == null) {
			jlb_logoImage = new JLabel(new ImageIcon(("./images/NerdsMap.png")));
	        jlb_logoImage.setLayout(new FlowLayout());
	        jlb_logoImage.setBounds(320, 75, 360, 200);
		}
		return jlb_logoImage;
	}

	private JButton getJButtonSignIn() {
		if (jb_signIn == null) {
			jb_signIn = new JButton();
			jb_signIn.setText("Entrar");
	        jb_signIn.setMargin(new Insets(1, 5, 1, 5));
	        jb_signIn.setBounds(500, 300, 80, 40); 
		}
		return jb_signIn;
	}

	private JPasswordField getJPasswordFieldPass() {
		if (jpf_pass == null) {
			jpf_pass = new JPasswordField();
			jpf_pass.setText("");
			jpf_pass.setEchoChar('•');
	        Font newTextFieldFont=new Font(jpf_pass.getFont().getName(),jpf_pass.getFont().getStyle(),18);   
	        jpf_pass.setFont(newTextFieldFont);  
			jpf_pass.setBounds(350, 250, 250, 30); 
		}
		return jpf_pass;
	}

	private JTextField getJTextFieldUser() {
		if (jtf_user == null) {
			jtf_user = new JTextField();
			jtf_user.setText("");
	        Font newTextFieldFont=new Font(jtf_user.getFont().getName(),jtf_user.getFont().getStyle(),18);  
	        jtf_user.setFont(newTextFieldFont); 
		    jtf_user.setBounds(350, 201, 250, 30);
		}
		return jtf_user;
	}

	private JLabel getJLabelUser() {
		if (jlb_user == null) {
			jlb_user = new JLabel();
			jlb_user.setText("Nro de Padrón");
			jlb_user.setForeground(Color.gray);
			jlb_user.setBounds(350, 188, 150, 10); 
		}
		return jlb_user;
	}
	
	public int getPadron() {
		
		return Integer.parseInt(jtf_user.getText());

	}
	
	public String getStringPadron() {
		return jtf_user.getText();
	}
	
	public String getPass() {
		return new String(jpf_pass.getPassword());
	}
	
	private JLabel getJLabelPass() {
		if (jlb_pass == null) {
			jlb_pass = new JLabel();
			jlb_pass.setText("Contraseña");
			jlb_pass.setForeground(Color.gray);
			jlb_pass.setBounds(350, 237, 100, 10); 
		}
		return jlb_pass;
	}
	
	   public void NewAccountActionListener(ActionListener listener) {
		   jb_newAccount.addActionListener(listener);
	   }
	   
	   public void LogInActionListener(ActionListener listener) {
		   jb_signIn.addActionListener(listener);
	   }

	   public JComponent getMainComponent() {
		   return mainPanel;
	   }

}
